#!/bin/bash
#
# supervisord   This scripts turns supervisord on
#
# Author:       Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
#
# chkconfig:	- 95 04
#
# description:  supervisor is a process control utility.  It has a web based
#               xmlrpc interface as well as a few other nifty features.
# processname:  supervisord
# config: /etc/supervisord.conf
# pidfile: /var/run/supervisord.pid
#

# source function library
. /etc/rc.d/init.d/functions
. /etc/profile

lock_file=/data/apps/var/supervisord/supervisord.lock
RETVAL=0
prog=supervisord

start() {
	echo -n $"Starting supervisord: "
	daemon /usr/bin/supervisord -c {{supervisor_prim_conf}}
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch ${lock_file}
}

stop() {
	echo -n $"Stopping supervisord: "
	killproc supervisord
	echo
	[ $RETVAL -eq 0 ] && rm -f ${lock_file}
}

reload(){
        echo -n $"Reloading $prog: "
        /usr/bin/supervisorctl -c {{supervisor_prim_conf}} reload
        RETVAL=$?
        echo
}


restart() {
	stop
	start
}

case "$1" in
  start)
	start
	;;
  stop) 
	stop
	;;
  reload)
        reload
        ;;
  restart|force-reload)
	restart
	;;
  condrestart)
	#[ -f /var/lock/subsys/supervisord ] && restart
	[ -f ${lock_file} ] && restart
	;;
  status)
	status supervisord
	RETVAL=$?
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
	exit 1
esac

exit $RETVAL
